package com.yh.controller;

import com.yh.Iservice.EmployeeService;
import com.yh.Iservice.LimitService;
import com.yh.entity.Employee;
import com.yh.entity.Limi;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpSession;
import javax.sound.midi.Soundbank;
import java.util.ArrayList;
import java.util.List;

/**
 * 
<p>Title:EmployeeController</p>
<p>Describtion:方</p>
<p>Company:云和</p>

 * @author Administrator
 *@date 2018年11月7日
 */
@Controller
@RequestMapping("employee")
public class EmployeeController {
    private Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private LimitService limitService;
    @RequestMapping("bglogin")
    public String bglogin(Model model, HttpSession session,
                          @RequestParam(value = "ename", required = false) String ename,
                          @RequestParam(value = "epassword", required = false) String epassword) {
        String status;
        System.out.println("ename"+ename+"-----"+"password"+epassword);
        Employee employee=employeeService.empLogin(ename,epassword);
        if (employee==null||employee.equals("")){
            status="账号密码有误";
            System.out.println("账号密码错误");
            model.addAttribute("status",status);
            return "bk_login";
        }else {
            //登陆成功
            System.out.println("登陆成功");
            //查询权限
            List limitList=limitService.limitByeid(employee.getEid());
            List list2=new ArrayList();
            for (int i=0;i<limitList.size();i++){
                Limi limi= (Limi) limitList.get(i);
                list2.add(limi.getMid());
            }
            //将list返回到页面
            session.setAttribute("listlimit",list2);
            model.addAttribute("emp",employee);
            //将登陆信息保存到session中
            session.setAttribute("globalemp",employee);
            return "redirect:../log/tologin.do";

        }
    }

}
